package com.ruoyi.easyfame.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.easyfame.domain.DemandViews;
import com.ruoyi.easyfame.service.IDemandViewsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 需求查看记录Controller
 * 
 * @author xhb
 * @date 2025-08-27
 */
@RestController
@RequestMapping("/easyfame/views")
public class DemandViewsController extends BaseController
{
    @Autowired
    private IDemandViewsService demandViewsService;

    /**
     * 查询需求查看记录列表
     */
    @PreAuthorize("@ss.hasPermi('easyfame:views:list')")
    @GetMapping("/list")
    public TableDataInfo list(DemandViews demandViews)
    {
        startPage();
        List<DemandViews> list = demandViewsService.selectDemandViewsList(demandViews);
        return getDataTable(list);
    }

    /**
     * 导出需求查看记录列表
     */
    @PreAuthorize("@ss.hasPermi('easyfame:views:export')")
    @Log(title = "需求查看记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DemandViews demandViews)
    {
        List<DemandViews> list = demandViewsService.selectDemandViewsList(demandViews);
        ExcelUtil<DemandViews> util = new ExcelUtil<DemandViews>(DemandViews.class);
        util.exportExcel(response, list, "需求查看记录数据");
    }

    /**
     * 获取需求查看记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('easyfame:views:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(demandViewsService.selectDemandViewsById(id));
    }

    /**
     * 新增需求查看记录
     */
    @PreAuthorize("@ss.hasPermi('easyfame:views:add')")
    @Log(title = "需求查看记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DemandViews demandViews)
    {
        return toAjax(demandViewsService.insertDemandViews(demandViews));
    }

    /**
     * 修改需求查看记录
     */
    @PreAuthorize("@ss.hasPermi('easyfame:views:edit')")
    @Log(title = "需求查看记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DemandViews demandViews)
    {
        return toAjax(demandViewsService.updateDemandViews(demandViews));
    }

    /**
     * 删除需求查看记录
     */
    @PreAuthorize("@ss.hasPermi('easyfame:views:remove')")
    @Log(title = "需求查看记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(demandViewsService.deleteDemandViewsByIds(ids));
    }
}
